/**
 * 两个点之间的信息
 */
let thatCopy;
const path = [
  [112.123385281677486, 33.442539170877272],
  [112.323385281677486, 33.542539170877272],
  [113.023385281677486, 33.742539170877272],
  [113.123385281677486, 33.942539170877272],
];

const polyline = new AMap.Polyline({
  path: path,
  isOutline: true,
  outlineColor: "#ffeeff",
  borderWeight: 3,
  strokeColor: "#3366FF",
  strokeOpacity: 1,
  strokeWeight: 6,
  // 折线样式还支持 'dashed'
  strokeStyle: "solid",
  // strokeStyle是dashed时有效
  strokeDasharray: [10, 5],
  lineJoin: "round",
  lineCap: "round",
  zIndex: 100,
});

// 蓝色小点url
const defaultIcon =
  "https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png";
// 红色小点url
const selectIcon =
  "https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png";

// 起始点
const marker1 = new AMap.Marker({
  icon: defaultIcon,
  position: path[0],
  offset: [-10, -31],
});

marker1.on("click", function (e) {
  console.log(e, 1);
  // 修改icon颜色
  marker1.setIcon(selectIcon);
});

const marker2 = new AMap.Marker({
  icon: defaultIcon,
  position: path[3],
  offset: [-10, -31],
});

marker2.on("click", function (e) {
  console.log(e, 2);
  marker2.setIcon(selectIcon);

  // 绘制曲线
  thatCopy.map.add([polyline]);

  setTimeout(() => {
    // 调用弹出弹窗
    thatCopy.showInfoA();
  }, 1000);
});
function dotInfoFun(that) {
  // map.setFitView();

  marker1.setMap(that.map);
  marker2.setMap(that.map);
  thatCopy = that;
}

export default dotInfoFun;
